//函数作为参数传递

//1、回调函数

var list = [1,4,8,6,5]
var a = list.sort(function (a,b) {
    return a-b;
});
console.log(a);
var b = list.sort(function (a, b) {
    return b-a;
});
console.log(b);

//函数作为返回值输出

var getSingle = function (fn) {
    var ret;
    return function () {
        return ret || (ret = fn.apply(this,arguments));
    };
};

var getScript = getSingle(function () {
    return new Object(); //document.createElement('script');
});


var s1 = getScript();
var s2 = getScript();

console.log(s1===s2);
